﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Engine;

namespace Game
{
    public class Bullet
    {
        public Model mModel;

        Vector3 mPosition;
        Vector3 mDirection;
        public bool wasFired;
        public int mDamage;
        int mSpeed;
        int mRange;
        float mTravelled;

        public Bullet(int speed)
        {
            mPosition = Vector3.Zero;
            mSpeed = speed;
            mDirection = new Vector3(0, 0, 0);
            mRange = 3000;
            wasFired = false;
            mDamage = 20;
        }

        public void Fire(Vector3 intialPos, Vector3 direction)
        {
            mPosition = intialPos;
            mDirection = direction;
            wasFired = true;
        }

        public void Update(GameTime time)
        {
            if (mTravelled > mRange)
            {
                wasFired = false;
                
            }

            if (wasFired)
            {
                mPosition += mDirection * 10;
                mTravelled += time.ElapsedGameTime.Milliseconds;
            }
        }

        public void Reset()
        {
            //mPosition = Vector3.Zero;
            mDirection = Vector3.Zero;
            mTravelled = 0;
            wasFired = false;
        }

        public void Draw(Matrix view, Matrix projection)
        { 
            Matrix world = Matrix.CreateTranslation(mPosition);
            ModelDrawer.Draw("Bullet", world, view, projection);
        }

        public Vector3 Position
        {
            get { return this.mPosition; }
            set { this.mPosition = value; }
        }
    }
}
